package com.ruoyi.crm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.crm.domain.CrmContract;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.domain.CrmAcceptanceSheet;
import com.ruoyi.crm.service.ICrmAcceptanceSheetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 验收Controller
 *
 * @author 最帅陈彬彬
 * @date 2024-12-06
 */
@RestController
@RequestMapping("/crm/sheet")
public class CrmAcceptanceSheetController extends BaseController {
    @Autowired
    private ICrmAcceptanceSheetService crmAcceptanceSheetService;

    /**
     * 查询验收列表
     */
//    @PreAuthorize("@ss.hasPermi('crm:sheet:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmAcceptanceSheet crmAcceptanceSheet) {
        startPage();
        List<CrmAcceptanceSheet> list = crmAcceptanceSheetService.selectCrmAcceptanceSheetList(crmAcceptanceSheet);
        return getDataTable(list);
    }

    /**
     * 导出验收列表
     */
//    @PreAuthorize("@ss.hasPermi('crm:sheet:export')")
    @Log(title = "验收", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmAcceptanceSheet crmAcceptanceSheet) {
        List<CrmAcceptanceSheet> list = crmAcceptanceSheetService.selectCrmAcceptanceSheetList(crmAcceptanceSheet);
        ExcelUtil<CrmAcceptanceSheet> util = new ExcelUtil<CrmAcceptanceSheet>(CrmAcceptanceSheet.class);
        util.exportExcel(response, list, "验收数据");
    }

    /**
     * 获取验收详细信息
     */
//    @PreAuthorize("@ss.hasPermi('crm:sheet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(crmAcceptanceSheetService.selectCrmAcceptanceSheetById(id));
    }

    /**
     * 新增验收
     */
//    @PreAuthorize("@ss.hasPermi('crm:sheet:add')")
    @Log(title = "验收", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmAcceptanceSheet crmAcceptanceSheet) {
        return toAjax(crmAcceptanceSheetService.insertCrmAcceptanceSheet(crmAcceptanceSheet));
    }

    /**
     * 修改验收
     */
//    @PreAuthorize("@ss.hasPermi('crm:sheet:edit')")
    @Log(title = "验收", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmAcceptanceSheet crmAcceptanceSheet)
    {
        return toAjax(crmAcceptanceSheetService.updateCrmAcceptanceSheet(crmAcceptanceSheet));
    }

    /**
     * 删除验收
     */
//    @PreAuthorize("@ss.hasPermi('crm:sheet:remove')")
    @Log(title = "验收", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(crmAcceptanceSheetService.deleteCrmAcceptanceSheetByIds(ids));
    }

    /**
     * 获取项目验收数据
     * @param
     * @return
     */
    @GetMapping("/getCrmAcceptanceSheetInfo/{projectId}")
    public AjaxResult getCrmAcceptanceSheetInfo(@PathVariable(value = "projectId") String projectId){
        CrmAcceptanceSheet sheet = crmAcceptanceSheetService.getOne(new LambdaQueryWrapper<CrmAcceptanceSheet>().eq(CrmAcceptanceSheet::getProjectId, projectId));
        return AjaxResult.success(sheet);
    }

    /**
     * 审核
     *
     * @param crmAcceptanceSheet
     * @return
     */
    @PostMapping("audit")
    public AjaxResult audit(@RequestBody CrmAcceptanceSheet crmAcceptanceSheet) {
        return AjaxResult.success(crmAcceptanceSheetService.audit(crmAcceptanceSheet));
    }
}
